# 1. OMP: Error Initializing libiomp5md.dll, but found libiomp5md.dll already initialized.

# 错误原因

OpenMP 运行时的多个副本已链接到程序中。这可能导致性能下降或不正确的结果

# 错误代码

OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized. OMP: Hint This means that multiple copies of the OpenMP runtime have been linked into the program. That is dangerous, since it can degrade performance or cause incorrect results. The best thing to do is to ensure that only a single OpenMP runtime is linked into the process, e.g. by avoiding static linking of the OpenMP runtime in any library. As an unsafe, unsupported, undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results. For more information, please see http://www.intel.com/software/products/support/.

# 解决方案

解决方法:代码前加入两行如下代码即可

import os
os.environ["KMP_DUPLICATE_LIB_OK"]  =  "TRUE"
1
2

# 2. YOLOv5中的"torchvision::nms"错误问题解决方法

# 错误原因

“torchvision::nms”是PyTorch库中的一个函数,用于实现非极大值抑制(Non-Maximum Suppression,NMS)。NMS是物体检测算法中的一个重要步骤,它能够帮助我们去除冗余的检测框,保留最佳的预测结果。 'torchvision::nms’无法在’cuda’后端运行。通常,这种问题出现在以下两种情况:

  1. PyTorch与Torchvision版本不匹配 如果正在使用的PyTorch版本和Torchvision版本之间存在不兼容性,就可能会遇到这个问题。这是因为Torchvision库的某些功能依赖于特定版本的PyTorch,当两者版本不匹配时,就可能导致问题。
  2. CUDA版本问题 另一种可能的原因是CUDA版本问题。具体来说,如果安装的CUDA版本与PyTorch或Torchvision所需的版本不符,也可能会出现此问题。

# 错误代码

NotImplementedError: Could not run 'torchvision::nms' with arguments from the 'CUDA' backend. This could be because the operator doesn't exist for this backend, or was omitted during the selective/custom build process (if using custom build). If you are a Facebook employee using PyTorch on mobile, please visit https://fburl.com/ptmfixes for possible resolutions. 'torchvision::nms' is only available for these backends

# 解决方案

  1. 确保PyTorch和Torchvision版本匹配
import torch
import torchvision
print(torch.__version__)      #返回纯数字是正确的
print(torchvision.__version__) # 返回纯数字是正确的 
1
2
3
4

返回数据类似这样的就是正常的。

如果里面有 cpu 这些字段就是版本不匹配,尽量不要安装最新版
2.0.0
0.15.0
1
2
3
  1. 如果发现版本不匹配,可以通过卸载,然后去pytorch重新安装,目前安装2.0比较正常:
pip uninstall torch torchvision  #卸载pytorch

1
2
  1. 确保CUDA版本和pytorch里需要的版本一样

下面命令查看cuda版本,如果cuda版本是1.8 ,那么在安装pytorch的时候就要选择1.8版本的cuda安装,pytorch网站上有对应的选项。

nvcc --version   
1

cuda版本可以低于 nvidia-smi里显卡显示的cuda版本,因为高版本的cuda可以兼容低版本的。

更新时间: 2024/7/30 17:14:28